package com.google.code.jmarias.server.phases;

import com.google.code.jmarias.common.action.DropTalonAction;
import com.google.code.jmarias.common.action.SignedAction;
import com.google.code.jmarias.common.NewPlayer;
import com.google.code.jmarias.common.NewTable;
import com.google.code.jmarias.server.tcp.MariasGame;

/**
 *
 * @author josef
 */
public class TalonDroppingPhase extends NewAbstractPhase {

    public TalonDroppingPhase(NewPlayer playingNow) {
        super(playingNow);

        addListener(new ActionListener(DropTalonAction.class) {

            @Override
            protected NewAbstractPhase processAction(SignedAction action, NewTable table) {

                // kontrola, jestli v talonu nejsou ostre karty

                broadcast(action);

                return new LonePlayerDecisionPhase(table.getPlayer(MariasGame.forehand));
            }
        });
    }

    @Override
    public String toString() {
        return "Odhozeni talonu";
    }


//    public AbstractPhase processAction(GameAction action) {
//        if (isSameAction(SendTalonAction.class, action)) {
//            return processSendTalonAction((SendTalonAction) action);
//        }
//        return null;
//    }
//
//    private AbstractPhase processSendTalonAction(SendTalonAction action) {
//        List<Card> talon = new ArrayList<Card>();
//        for (Card card : action.getCards()) {
//            talon.add(card);
//        }
//        if (table == null) {
//            System.out.println("SERVER CHECK: table is NULL!");
//        }
//        table.setTalon(talon);
//        Player[] players = table.getPlayers();
//        if (players[0] == null) {
//            System.out.println("SERVER CHECK: players[0] really is null!");
//        }
//        players[0].removeCards(talon);
//        //nasledujici akce je posilana, aby se klient dozvedel, ze je na case hrat dal
//        table.getClients().get(0).sendMessage(new AskForChoiceAction(0));
//        return new LonePlayerDecisionPhase();
//    }
}
